#include <iostream>
using namespace std;

const int N = 1010;

int n, m;
char a[N], b[N];
int f[N][N];

int main()
{
    freopen("cin.txt", "r", stdin);
    cin >> n >> a + 1 >> m >> b + 1;
    for (int i = 1; i <= n; i++)
        f[i][0] = i;
    for (int i = 1; i <= m; i++)
        f[0][i] = i;
    /*多了直接删，少了直接插，这样就最快*/
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            f[i][j] = min(f[i - 1][j] + 1, f[i][j - 1] + 1); //先比较插入和删除
            if (a[i] == b[j])                                //不必要求等长，毕竟。。。可以插入嘛
                f[i][j] = min(f[i - 1][j - 1], f[i][j]);
            else
                f[i][j] = min(f[i - 1][j - 1] + 1, f[i][j]); //修改
        }
    cout << f[n][m];
    return 0;
}